//
//  CustomTF2.m
//  kuaiyi
//
//  Created by Zhu Jinxin on 16/7/6.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "CustomTF2.h"

@implementation CustomTF2

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.bounds = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width -20 , 50);
        
        //Button1 => 左边的Button
        
        _button1 = [[UIButton alloc]init];
        _button1.titleLabel.font = FONT(16);
        [_button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_button1 setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
        
        [_button1 setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
        
        [_button1 sizeToFit];
        
        [_button1 addTarget:self action:@selector(selected1:) forControlEvents:UIControlEventTouchUpInside];
        
        
        //---------右边的Button---------------------------
        
        _button2 = [[UIButton alloc]init];
        _button2.titleLabel.font = FONT(16);
        [_button2 addTarget:self action:@selector(selected2:) forControlEvents:UIControlEventTouchUpInside];
        
        [_button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        
        [_button2 setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
        
        [_button2 setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
        
        [_button2 sizeToFit];
        
        
        [self addSubview:_button2];
        [self addSubview:_button1];
        
        
        [_button2 makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.offset(-20);
            make.centerY.equalTo(self);
            
        }];
        
        [_button1 makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.equalTo(_button2.left).offset(-20);
            make.centerY.equalTo(self);
            
        }];
        
    };
    
    
    return self;
}



- (void)selected1:(UIButton*)sender{
    
    
    sender.selected = YES;
    _button2.selected = NO;
    
    
    [self setTitle:sender.titleLabel.text forState:UIControlStateNormal];
    
    
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    if ([sender.titleLabel.text isEqualToString:@" 接受过"]) {
        
        if (_showBlcok) {
            _showBlcok();
        }
        
    }
    
    
}

- (void)selected2:(UIButton*)sender{
    
    sender.selected = YES;
    _button1.selected = NO;
    
    [self setTitle:sender.titleLabel.text forState:UIControlStateNormal];
    
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    if ([sender.titleLabel.text isEqualToString:@" 未接受过"]) {
        
        if (_hiddenBlcok) {
            _hiddenBlcok();
        }
        
    }
    
    
}



@end
